<?php
include_once 'module/conn.php';
include_once 'common/tools.php';

$matchId = $_GET["matchId"];
@ $teamName = $_GET["teamName"];
@ $userId = $_GET["id"];
$userIp = $_SERVER["REMOTE_ADDR"];
$userMac = $_GET["mac"];

$config = require 'conf/config.ini.php';
$conn = mysql_connect($config["DB_HOST"], $config["DB_USER"], $config["DB_PWD"]);
mysql_select_db($config["DB_NAME"], $conn);
mysql_query("SET NAMES utf8");

if ($teamName != "null") {

	if ($userId == "null") {
		$userId = null;
	}

	//记录支持信息
	$sql = "insert into live_team_favor (matchId,teamName,userId,userIp,userMac) values ('" . $matchId . "', '" . $teamName . "', '" . $userId . "', '" . $userIp . "', '" . $userMac . "') ON DUPLICATE KEY UPDATE userId='" . $userId . "', teamName='" . $teamName . "'";

	mysql_query($sql, $conn);
}
$sql = "select teamName, count(teamName) count from live_team_favor where matchId = '" . $matchId . "' group by teamName";

$result = mysql_query($sql, $conn);

//启用一个带有ob_gzip压缩机的工作台
ob_start('ob_gzip');
if (mysql_num_rows($result) > 0) {
	while ($favor = mysql_fetch_object($result)) {
		$favorArray[] = $favor;
	}
	echo '{"sql":"' . $sql . '","result":"Y","results":' . json_encode($favorArray) . '}';

} else {
	echo '{"sql":"' . $sql . '","result":"N"}';
}

//输出压缩成果
ob_end_flush();
?>